package com.xp.framework.server;


import com.xp.framework.Config;
import com.xp.framework.RpcInvokerHandler;

import java.util.Map;
import java.util.Set;

/**
 * @author xuecx
 * @Date 2019/4/30 15:02
 */
public class ServerProxy {

    private AbstractChildServer childServer;
    private Config config;

    public ServerProxy(AbstractChildServer childServer, Config config) {
        this.childServer = childServer;
        this.config = config;
    }

    public void export() {
        try {
            ServerConfig serverConfig = (ServerConfig) this.config;
            Map<String, String> ref = serverConfig.getRef();
            Set<String> strings = ref.keySet();
            for (String key : strings) {
                Object serviceBean = Class.forName((String) key).newInstance();
                RpcInvokerHandler.serviceMap.put((String) ref.get(key), serviceBean);
            }
            this.childServer.start(this.config);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
